package com.jlnk.androidfmc.entity;

import android.os.Parcel;
import android.os.Parcelable;

import org.json.JSONException;
import org.json.JSONObject;


public class ZNews  implements Parcelable {

    private String title;
    private String imageUrl; // 图片URL或资源ID
    private String content;

    // 构造函数
    public ZNews(String title, String imageUrl, String content) {
        this.title = title;
        this.imageUrl = imageUrl;
        this.content = content;
    }

    // 获取标题
    public String getTitle() {
        return title;
    }

    // 设置标题
    public void setTitle(String title) {
        this.title = title;
    }

    // 获取图片
    public String getImageUrl() {
        return imageUrl;
    }

    // 设置图片
    public void setImageUrl(String imageUrl) {
        this.imageUrl = imageUrl;
    }

    // 获取内容
    public String getContent() {
        return content;
    }

    // 设置内容
    public void setContent(String content) {
        this.content = content;
    }

    // Parcelable 接口实现
    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(title);
        dest.writeString(imageUrl);
        dest.writeString(content);
    }

    protected ZNews(Parcel in) {
        title = in.readString();
        imageUrl = in.readString();
        content = in.readString();
    }

    public static final Parcelable.Creator<ZNews> CREATOR = new Parcelable.Creator<ZNews>() {
        @Override
        public ZNews createFromParcel(Parcel source) {
            return new ZNews(source);
        }

        @Override
        public ZNews[] newArray(int size) {
            return new ZNews[size];
        }
    };

    // 将 ZNews 对象转换为 JSON 字符串
    public String toJson() {
        JSONObject json = new JSONObject();
        try {
            json.put("title", title);
            json.put("imageUrl", imageUrl); // 使用新的属性名
            json.put("content", content);
        } catch (JSONException e) {
            e.printStackTrace();
            // 可以返回空字符串或者错误信息
            return "";
        }
        return json.toString();
    }
}